import { appTasks } from '@ohos/hvigor-ohos-plugin'
import { hvigor, HvigorNode, getNode } from '@ohos/hvigor'
import { preCommit } from './scripts/gitHooks.ts'
import { issueAdd, issueClear, generateModule, issueAddAll } from './scripts/issueTasks.ts'

// 获取当前hvigorNode节点对象
const node: HvigorNode = getNode(__filename)

/**
 * 自动执行git hooks
 */
hvigor.buildFinished(buildResult => {
  runGitHooks(node);
})

function runGitHooks(node) {
  console.log('run git hooks...')
  preCommit(node);
}

/**
 * 注册 issueAdd 任务
 * 用于生成issue模块的编译配置文件并添加到构建配置中
 */
node.registerTask({
  name: 'issueAdd',
  run() {
    issueAdd(node)
  }
})

/**
 * 注册 issueAdd 任务
 * 用于生成issue模块的编译配置文件并添加到构建配置中
 */
node.registerTask({
  name: 'issueAddAll',
  run() {
    issueAddAll(node)
  }
})

/**
 * 注册 issueClear 任务
 * 用于清理所有issue相关配置
 */
node.registerTask({
  name: 'issueClear',
  run() {
    issueClear(node)
  }
})

/**
 * 注册生成模块任务
 * 用于创建新模块
 */
node.registerTask({
  name: 'generateModule',
  run() {
    generateModule(node);
  }
})

export default {
  system: appTasks,
  plugins: []
}